package com.ruleengine.db.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
import com.ruleengine.db.service.RulerelationService;
import com.ruleengine.db.mapper.RulerelationMapper;
import com.ruleengine.db.model.Rulerelation;

/**
 * @author lianghanwei on 2024/3/17
 */
@Service
public class RulerelationServiceImpl extends ServiceImpl<RulerelationMapper, Rulerelation> implements RulerelationService {
    private final RulerelationMapper rulerelationMapper;

    public RulerelationServiceImpl(RulerelationMapper rulerelationMapper) {
        this.rulerelationMapper = rulerelationMapper;
    }

    @Override
    public List<Rulerelation> getRulerelations(String tenantId, String rulechainId) {
        return ChainWrappers.lambdaQueryChain(rulerelationMapper)
            .eq(Rulerelation::getTenantId, tenantId)
            .eq(Rulerelation::getRulechainId, rulechainId)
            .list();
    }

    @Override
    public boolean softDeleteRulerelationsByRulechainId(String tenantId, String rulechainId) {
        return ChainWrappers.lambdaUpdateChain(rulerelationMapper)
            .eq(Rulerelation::getTenantId, tenantId)
            .eq(Rulerelation::getRulechainId, rulechainId)
            .remove();
    }
}
